<!--
 * @Descripttion: 
 * @Author: yuxi
 * @Date: 2022-10-02 21:35:02
 * @LastEditors: yuxi
 * @LastEditTime: 2022-10-05 21:54:03
-->
<template>
  <div class="demo">
    <el-container>
      <el-aside width="200px" style="overflow-x: hidden">
        <el-menu
          :default-active="defaultActive"
          @select="to"
          class="el-menu-vertical-demo"
        >
          <el-submenu
            v-for="(menus, menuName) in componentMenus"
            :index="menuName"
            :key="menuName"
          >
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span slot="title">{{ menuName }}</span>
            </template>
            <el-menu-item
              v-for="menu in menus"
              :index="menu.name"
              :key="menu.name"
            >
              <span slot="title">{{ menu.title }}</span>
            </el-menu-item>
          </el-submenu>
          <!-- <el-menu-item v-for="(menu) in componentMenus" :index="menu.name" :key="menu.name">
            <i class="el-icon-menu"></i>
            <span slot="title">{{menu.title}}</span>
          </el-menu-item>  -->
        </el-menu>
      </el-aside>
      <el-container>
        <el-main class="main-contaienr">
          <router-view></router-view>
        </el-main>        
      </el-container>
    </el-container>
    <codeDocs></codeDocs>
  </div>
</template>

<script>
import { componentRouters } from './index.js' 
import codeDocs from '../docs/code'

export default {
  name: 'layout',
  title: 'layout',
  components: {
    codeDocs
  },
  computed: {
    componentMenus () {
      console.log(componentRouters)
      let categorys = {}
      componentRouters.map((c) => {
        let category = c.category || '其他'
        categorys[category] = categorys[category] || []
        categorys[category].push(c)
      })
      console.log(categorys)
      return categorys // componentRouters
    },
    defaultActive () {
      let defaultActive = this.$route.name
      return defaultActive
    },
  },
  methods: {
    to (menu) {
      console.log(menu)
      this.$router.push({
        name: menu,
      })
    },
  },
}
</script>

<style lang="less" scoped>
.el-menu-vertical-demo {
  height: 100vh;
  text-align: left;
}

.main-contaienr {
  padding: 0;
  overflow: hidden auto;
}

.markdown-body {
  text-align: left;
}
</style>
